from django.http import HttpResponse
# from rest_framework.response import Response
from django.http import JsonResponse
from . import similarityApi
import json


def get_similarity(request):
    if request.method == 'GET':
        request.params = request.GET
        return JsonResponse({"status": "ok"})

    elif request.method == 'POST':
        request.params = json.loads(request.body)
        print(request.body)
        # image_path1 = request.params['imagePath1']
        # image_path2 = request.params['imagePath2']
        # similarity = similarityApi.get_cos_similarity(image_path1, image_path2)
        # 传来二进制流
        image1 = request.params['image1']
        image2 = request.params['image2']
        similarity = similarityApi.get_cos_similarity(image1, image2)
        return JsonResponse({"similarity": similarity})

    # print(request.params)
